var hs_const_domain = {
    aa: function(a) {
        return "http://" + a + ".hongshu.com";
    },
    hostName: "http://www.hongshu.com",
    waphostName: "http://g.hongshu.com",
    vipHostName: "http://vip.hongshu.com",
    mmHostName: "http://mm.hongshu.com",
    ggHostName: "http://gg.hongshu.com",
    payHostName: "http://pay.hongshu.com",
    commentHostName: "http://www.hongshu.com",
    authorHostName: "http://www.hongshu.com",
    passportHostName: "https://i.hongshu.com",
    resourceHost: "http://img1.hongshu.com",
    saferesourceHost: "https://img2.hongshu.com",
    userHost: "https://i.hongshu.com",
    homeHost: "http://www.hongshu.com",
    payHost: "https://wallet.hongshu.com",
    bookHost: "http://www.hongshu.com",
    host: location.host,
    cookieprefix: 'hsc'
};
var hs_const_url = {
    ajax_flushmoney: hs_const_domain.passportHostName + '/userajax.do?method=flushmoney&',
    ajax_userinfo: hs_const_domain.passportHostName + '/userajax.do?method=getloginfo',
    login: hs_const_domain.passportHostName + '/login.html',
    logout: hs_const_domain.passportHostName + '/logout.html',
    bookajax: hs_const_domain.hostName + '/bookajax.do',
    userajax: hs_const_domain.passportHostName + '/userajax.do',
    homeajax: hs_const_domain.hostName + '/homeajax.do',
    bookface: hs_const_domain.resourceHost + '/bookface',
    userface: hs_const_domain.resourceHost + '/avatar',
    safebookface: hs_const_domain.saferesourceHost + '/bookface',
    safeuserface: hs_const_domain.saferesourceHost + '/avatar',
    staticres: hs_const_domain.resourceHost + "/Public",
    usercenter: hs_const_domain.passportHostName + '/profile/center.do',
    userset: hs_const_domain.passportHostName + '/userset.do',
    authorcenter: hs_const_domain.hostName + '/userspace',
    qq_login: hs_const_domain.passportHostName + '/third/qq/login.html',
    weibo_login: hs_const_domain.passportHostName + '/third/sina/login.html',
    baidu_login: hs_const_domain.passportHostName + '/third/baidu/login.html',
    wexin_login: hs_const_domain.passportHostName + '/third/wechat/login.html',
    tjsitecount_js: hs_const_domain.resourceHost + '/Public/javascript/tjsitecount.js',
    refsitecounturl: hs_const_domain.hostName + '/sitecount/ref.do',
    clicktrackerurl: hs_const_domain.hostName + '/sitecount/click.do'
};
var hs_const_message = {
    exchangecard: {
        '1': '红薯银币兑换成功',
        '2': '红薯豆兑换成功',
        '-1': '兑换失败',
        '-2': '卡号有误',
        '-3': '该卡已兑换过',
        '-4': '该卡已过期',
        '-5': '本月不能兑换该卡,请到兑换期时兑换',
        '-6': '请勿兑换其他人的卡',
        '-7': '红薯卡号不能为空',
        '-8': '每月第一天凌晨0点至早11点时红薯卡兑换暂停',
        '-9': "红薯卡长度不对"
    }
};
var logstatic = {
    arrImg: [],
    maxLength: 4,
    taskQueue: [],
    log: function(posi, operate, details, serverUrl) {
        var me = this,
        p, v, detailData = [],
        logUrl = (serverUrl || hs_const_url.clicktrackerurl);
        if (details != null) {
            for (p in details) {
                if (details.hasOwnProperty(p)) {
                    v = details[p];
                    detailData.push(('"' + p + '":') + '"' + v + '"');
                }
            }
        }
        me.send(logUrl + "?t=" + (new Date().getTime()) + "&position=" + encodeURIComponent(posi) + "&operation=" + encodeURIComponent(operate) + "&details=" + encodeURIComponent(detailData.join(',')));
    },
    send: function(url) {
        if (typeof(url) == "undefined" || url == "") return;
        var me = this,
        img, imgHandler, arrImg, len = 0,
        index = -1;
        arrImg = me.arrImg;
        len = arrImg.length;
        for (var i = 0; i < len; i++) {
            if (arrImg[i].f == 0) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            if (len == me.maxLength) {
                me.taskQueue.push(url);
                return;
            }
            img = $(new Image());
            arrImg.push({
                f: 1,
                img: img
            });
            index = (len == 0 ? 0 : len);
        } else {
            img = arrImg[index].img;
        }
        arrImg[index].f = 1;
        img.data("vid", index);
        imgHandler = function() {
            var vid = $(this).data("vid");
            if (vid >= 0) {
                arrImg[vid].f = 0;
            }
            if (me.taskQueue.length > 0) {
                me.send(me.taskQueue.shift());
            }
        };
        img.unbind().load(imgHandler).error(imgHandler);
        $(img).attr("src", url);
    }
};;
var clicktracker = (function() {
    var _ref = '';
    var _url = '';
    var SEED_NAME = "clktrack";
    var DATA_SEED_NAME = "data-clktrack";
    var hasInit = 0;
    var getAttribute = function(element, attribute_name) {
        if (element && element.nodeType === 1 && element.getAttribute) {
            try {
                return element.getAttribute(attribute_name, 2);
            } catch(ex) {}
        }
        return null;
    };
    var hasAttribute = function(element, attribute_name) {
        return element && element.nodeType === 1 && element.hasAttribute ? element.hasAttribute(attribute_name) : getAttribute(element, attribute_name) !== null
    };
    var getTarget = function(evt) {
        var node = evt.target || evt.srcElement;
        try {
            if (node && node.nodeType === 3) {
                return node.parentNode;
            }
        } catch(ex) {}
        return node;
    };
    var hasSeed = function(node) {
        return hasAttribute(node, SEED_NAME) || hasAttribute(node, DATA_SEED_NAME);
    };
    var getSeed = function(node) {
        return getAttribute(node, SEED_NAME) || getAttribute(node, DATA_SEED_NAME);
    };
    var clickHandler = function(evt) {
        var node = getTarget(evt);
        if (!node || !node.nodeType) {
            return;
        }
        while (node && node.nodeName !== 'HTML' && !hasSeed(node)) {
            node = node.parentNode;
        }
        if (!node || node.nodeType !== 1 || node.nodeName === 'HTML') {
            return;
        }
        var seed = getSeed(node);
        var data = {
            ref: _ref,
            url: _url
        };
        logstatic.log(seed, "click", data, hs_const_url.clicktrackerurl);
    }
    var addEventListener = function(element, eventName, handler) {
        if (!element) {
            return;
        }
        if (element.addEventListener) {
            element.addEventListener(eventName, handler, false);
        } else if (element.attachEvent) {
            element.attachEvent('on' + eventName,
            function(evt) {
                handler.call(element, evt);
            });
        }
    };
    var init = function() {
        if (window.parent != window.self) {
            try {
                _ref = parent.document.referrer;
            } catch(err) {
                _ref = document.referrer;
            }
            try {
                _url = parent.document.location;
            } catch(err) {
                _url = document.location;
            }
        } else {
            _ref = document.referrer || '';
            _url = document.location;
        }
        var doc = window.document;
        if (hasInit) return;
        addEventListener(doc, 'mousedown', clickHandler);
        addEventListener(doc, 'touchstart', clickHandler);
        hasInit = 1;
    };
    return {
        init: init
    }
})();;
/*!art-template - Template Engine | http://aui.github.com/artTemplate/*/
!
function() {
    function a(a) {
        return a.replace(t, "").replace(u, ",").replace(v, "").replace(w, "").replace(x, "").split(y)
    }
    function b(a) {
        return "'" + a.replace(/('|\\)/g, "\\$1").replace(/\r/g, "\\r").replace(/\n/g, "\\n") + "'"
    }
    function c(c, d) {
        function e(a) {
            return m += a.split(/\n/).length - 1,
            k && (a = a.replace(/\s+/g, " ").replace(/<!--[\w\W]*?-->/g, "")),
            a && (a = s[1] + b(a) + s[2] + "\n"),
            a
        }
        function f(b) {
            var c = m;
            if (j ? b = j(b, d) : g && (b = b.replace(/\n/g,
            function() {
                return m++,
                "$line=" + m + ";"
            })), 0 === b.indexOf("=")) {
                var e = l && !/^=[=#]/.test(b);
                if (b = b.replace(/^=[=#]?|[\s;]*$/g, ""), e) {
                    var f = b.replace(/\s*\([^\)]+\)/, "");
                    n[f] || /^(include|print)$/.test(f) || (b = "$escape(" + b + ")")
                } else b = "$string(" + b + ")";
                b = s[1] + b + s[2]
            }
            return g && (b = "$line=" + c + ";" + b),
            r(a(b),
            function(a) {
                if (a && !p[a]) {
                    var b;
                    b = "print" === a ? u: "include" === a ? v: n[a] ? "$utils." + a: o[a] ? "$helpers." + a: "$data." + a,
                    w += a + "=" + b + ",",
                    p[a] = !0
                }
            }),
            b + "\n"
        }
        var g = d.debug,
        h = d.openTag,
        i = d.closeTag,
        j = d.parser,
        k = d.compress,
        l = d.escape,
        m = 1,
        p = {
            $data: 1,
            $filename: 1,
            $utils: 1,
            $helpers: 1,
            $out: 1,
            $line: 1
        },
        q = "".trim,
        s = q ? ["$out='';", "$out+=", ";", "$out"] : ["$out=[];", "$out.push(", ");", "$out.join('')"],
        t = q ? "$out+=text;return $out;": "$out.push(text);",
        u = "function(){var text=''.concat.apply('',arguments);" + t + "}",
        v = "function(filename,data){data=data||$data;var text=$utils.$include(filename,data,$filename);" + t + "}",
        w = "'use strict';var $utils=this,$helpers=$utils.$helpers," + (g ? "$line=0,": ""),
        x = s[0],
        y = "return new String(" + s[3] + ");";
        r(c.split(h),
        function(a) {
            a = a.split(i);
            var b = a[0],
            c = a[1];
            1 === a.length ? x += e(b) : (x += f(b), c && (x += e(c)))
        });
        var z = w + x + y;
        g && (z = "try{" + z + "}catch(e){throw {filename:$filename,name:'Render Error',message:e.message,line:$line,source:" + b(c) + ".split(/\\n/)[$line-1].replace(/^\\s+/,'')};}");
        try {
            var A = new Function("$data", "$filename", z);
            return A.prototype = n,
            A
        } catch(B) {
            throw B.temp = "function anonymous($data,$filename) {" + z + "}",
            B
        }
    }
    var d = function(a, b) {
        return "string" == typeof b ? q(b, {
            filename: a
        }) : g(a, b)
    };
    d.version = "3.0.0",
    d.config = function(a, b) {
        e[a] = b
    };
    var e = d.defaults = {
        openTag: "<%",
        closeTag: "%>",
        escape: !0,
        cache: !0,
        compress: !1,
        parser: null
    },
    f = d.cache = {};
    d.render = function(a, b) {
        return q(a, b)
    };
    var g = d.renderFile = function(a, b) {
        var c = d.get(a) || p({
            filename: a,
            name: "Render Error",
            message: "Template not found"
        });
        return b ? c(b) : c
    };
    d.get = function(a) {
        var b;
        if (f[a]) b = f[a];
        else if ("object" == typeof document) {
            var c = document.getElementById(a);
            if (c) {
                var d = (c.value || c.innerHTML).replace(/^\s*|\s*$/g, "");
                b = q(d, {
                    filename: a
                })
            }
        }
        return b
    };
    var h = function(a, b) {
        return "string" != typeof a && (b = typeof a, "number" === b ? a += "": a = "function" === b ? h(a.call(a)) : ""),
        a
    },
    i = {
        "<": "&#60;",
        ">": "&#62;",
        '"': "&#34;",
        "'": "&#39;",
        "&": "&#38;"
    },
    j = function(a) {
        return i[a]
    },
    k = function(a) {
        return h(a).replace(/&(?![\w#]+;)|[<>"']/g, j)
    },
    l = Array.isArray ||
    function(a) {
        return "[object Array]" === {}.toString.call(a)
    },
    m = function(a, b) {
        var c, d;
        if (l(a)) for (c = 0, d = a.length; d > c; c++) b.call(a, a[c], c, a);
        else for (c in a) b.call(a, a[c], c)
    },
    n = d.utils = {
        $helpers: {},
        $include: g,
        $string: h,
        $escape: k,
        $each: m
    };
    d.helper = function(a, b) {
        o[a] = b
    };
    var o = d.helpers = n.$helpers;
    d.onerror = function(a) {
        var b = "Template Error\n\n";
        for (var c in a) b += "<" + c + ">\n" + a[c] + "\n\n";
        "object" == typeof console && console.error(b)
    };
    var p = function(a) {
        return d.onerror(a),
        function() {
            return "{Template Error}"
        }
    },
    q = d.compile = function(a, b) {
        function d(c) {
            try {
                return new i(c, h) + ""
            } catch(d) {
                return b.debug ? p(d)() : (b.debug = !0, q(a, b)(c))
            }
        }
        b = b || {};
        for (var g in e) void 0 === b[g] && (b[g] = e[g]);
        var h = b.filename;
        try {
            var i = c(a, b)
        } catch(j) {
            return j.filename = h || "anonymous",
            j.name = "Syntax Error",
            p(j)
        }
        return d.prototype = i.prototype,
        d.toString = function() {
            return i.toString()
        },
        h && b.cache && (f[h] = d),
        d
    },
    r = n.$each,
    s = "break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield,undefined",
    t = /\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|\s*\.\s*[$\w\.]+/g,
    u = /[^\w$]+/g,
    v = new RegExp(["\\b" + s.replace(/,/g, "\\b|\\b") + "\\b"].join("|"), "g"),
    w = /^\d[^,]*|,\d[^,]*/g,
    x = /^,+|,+$/g,
    y = /^$|,+/;
    e.openTag = "{{",
    e.closeTag = "}}";
    var z = function(a, b) {
        var c = b.split(":"),
        d = c.shift(),
        e = c.join(":") || "";
        return e && (e = ", " + e),
        "$helpers." + d + "(" + a + e + ")"
    };
    e.parser = function(a) {
        a = a.replace(/^\s/, "");
        var b = a.split(" "),
        c = b.shift(),
        e = b.join(" ");
        switch (c) {
        case "if":
            a = "if(" + e + "){";
            break;
        case "else":
            b = "if" === b.shift() ? " if(" + b.join(" ") + ")": "",
            a = "}else" + b + "{";
            break;
        case "/if":
            a = "}";
            break;
        case "each":
            var f = b[0] || "$data",
            g = b[1] || "as",
            h = b[2] || "$value",
            i = b[3] || "$index",
            j = h + "," + i;
            "as" !== g && (f = "[]"),
            a = "$each(" + f + ",function(" + j + "){";
            break;
        case "/each":
            a = "});";
            break;
        case "echo":
            a = "print(" + e + ");";
            break;
        case "print":
        case "include":
            a = c + "(" + b.join(",") + ");";
            break;
        default:
            if (/^\s*\|\s*[\w\$]/.test(e)) {
                var k = !0;
                0 === a.indexOf("#") && (a = a.substr(1), k = !1);
                for (var l = 0,
                m = a.split("|"), n = m.length, o = m[l++]; n > l; l++) o = z(o, m[l]);
                a = (k ? "=": "=#") + o
            } else a = d.helpers[c] ? "=#" + c + "(" + b.join(",") + ");": "=" + a
        }
        return a
    },
    "function" == typeof define ? define(function() {
        return d
    }) : "undefined" != typeof exports ? module.exports = d: this.template = d
} ();;
template.helper('get_user_avatar_url',
function(_uid, _size) {
    return getUserFacePath(_uid, _size);
});
template.helper('get_user_avatar_safe_url',
function(_uid, _size) {
    return getUserFaceSafePath(_uid, _size);
});
template.helper('getbookface',
function(_bid, _size) {
    return getBookfacePath(_bid, _size);
});
template.helper('getbookfacesafe',
function(_bid, _size) {
    return getBookfaceSafePath(_bid, _size);
});
template.helper('getDateDiff',
function(timespan) {
    return getDateDiff(timespan);
});
template.helper('toThousands',
function(num) {
    return toThousands(num);
});
template.helper('htmldecode',
function(html) {
    return htmldecode(html);
});
template.helper('encodeURIComponent',
function(url) {
    return encodeURIComponent(url);
});
function getDateDiff(dateTimeStamp) {
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = parseInt(now) - parseInt(dateTimeStamp + "000");
    if (diffValue < 0) {
        return;
    }
    var monthC = diffValue / month;
    var weekC = diffValue / (7 * day);
    var dayC = diffValue / day;
    var hourC = diffValue / hour;
    var minC = diffValue / minute;
    if (monthC >= 1) {
        result = parseInt(monthC) + "个月前";
    } else if (weekC >= 1) {
        result = parseInt(weekC) + "周前";
    } else if (dayC >= 1) {
        result = parseInt(dayC) + "天前";
    } else if (hourC >= 1) {
        result = parseInt(hourC) + "个小时前";
    } else if (minC >= 1) {
        result = parseInt(minC) + "分钟前";
    } else {
        result = parseInt(minC) + "分钟内";
    }
    return result;
};
var CookieUtil = {
    trim: function(s) {
        return (s != null ? s.replace(/(^\s*)|(\s*$)/g, "") : "");
    },
    setCookie: function(cookie) {
        var expires = "";
        if (cookie.value == null) {
            cookie.value = "";
            cookie.expires = -1;
        }
        if (cookie.expires != null) {
            var date = null;
            if (typeof(cookie.expires) == "number") {
                date = new Date();
                date.setTime(date.getTime() + (parseInt(cookie.expires) * 1000));
            } else if (cookie.expires.toUTCString != null) {
                date = cookie.expires;
            }
            expires = "; expires=" + date.toUTCString();
        }
        var path = cookie.path ? "; path=" + (cookie.path) : "";
        var domain = cookie.domain ? "; domain=" + (cookie.domain) : "";
        var secure = cookie.secure ? "; secure": "";
        document.cookie = [hs_const_domain.cookieprefix + cookie.name, "=", (cookie.value != null ? encodeURIComponent(cookie.value) : ""), expires, path, domain, secure].join("");
    },
    getCookie: function(name) {
        var value = null;
        if (document.cookie && document.cookie != "") {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = this.trim(cookies[i]);
                if (cookie.substring(0, (hs_const_domain.cookieprefix + name).length + 1) == ((hs_const_domain.cookieprefix + name) + "=")) {
                    value = decodeURIComponent(cookie.substring((hs_const_domain.cookieprefix + name).length + 1));
                    break;
                }
            }
        }
        return value;
    },
    getDomain: function() {
        var a = [""];
        var b = window.location.host.split(".");
        var j = (b.length >= 3 ? (b.length - 2) : 0);
        for (var i = 1; j < b.length; j++) {
            a[i++] = b[j];
        }
        return a.join(".");
    }
};
if (window.Class == null || window.Class == undefined) {
    window.Class = {};
}
window.Class.getInstance = function(constructor, parent) {
    return (parent != null ? new parent() : new(function() {})());
};
function Listener() {
    this.listeners = [];
}
Listener.prototype.addListener = function(listener) {
    this.listeners[this.listeners.length] = listener;
};
Listener.prototype.removeListener = function(listener) {
    var listeners = this.listeners;
    if (listeners != null) {
        var index = -1;
        for (var i = 0,
        length = listeners.length; i < length; i++) {
            if (listener == listeners[i]) {
                index = i;
                break;
            }
        }
        if (index > -1) {
            for (var i = index,
            length = listeners.length - 1; i < length; i++) {
                listeners[i] = listeners[i + 1];
            }
            listeners[listeners.length - 1] = null;
            listeners.length = listeners.length - 1;
            return listener;
        }
    }
    return null;
};
Listener.prototype.trigger = function() {
    var listeners = this.listeners;
    if (listeners != null) {
        for (var i = 0,
        length = listeners.length; i < length; i++) {
            try {
                var flag = listeners[i].apply(this, arguments);
                if (flag != null && flag != undefined && flag == false) {
                    break;
                }
            } catch(e) {
                throw e;
            }
        }
    }
};
window.Timer = function(target, method, interval) {
    this.status = 0;
    this.target = target;
    this.method = method;
    this.interval = interval;
};
Timer.prototype.getTask = function() {
    if (this.timer == null) {
        var instance = this;
        this.task = function() {
            instance.run();
        };
    }
    return this.task;
};
Timer.prototype.start = function(interval) {
    if (this.status == 0) {
        this.status = 1;
        this.run(interval);
    }
};
Timer.prototype.pause = function(interval) {
    var result = this.status;
    this.status = 0;
    if (this.timer != null) {
        clearTimeout(this.timer);
        this.timer = null;
    }
    return result;
};
Timer.prototype.stop = function() {
    this.pause();
};
Timer.prototype.run = function(interval) {
    if (this.timer != null) {
        clearTimeout(this.timer);
        this.timer = null;
    }
    if (this.status == 1) {
        if (interval != null) {
            this.timer = setTimeout(this.getTask(), interval);
            return;
        }
        this.method.call(this.target);
        if (this.test != null && this.test() == false) {
            return;
        }
        this.timer = setTimeout(this.getTask(), this.interval);
    }
};
var StringUtil = {
    checkEmail: function(email) {
        if (!email.match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) {
            return false;
        }
        return true;
    },
    checkPhone: function(phone) {
        if (!phone.match(/^1[3|4|5|8][0-9]\d{4,8}$/)) {
            return false;
        }
        return true;
    },
    stringToDateTime: function(postdate) {
        var second = 1000;
        var minutes = second * 60;
        var hours = minutes * 60;
        var days = hours * 24;
        var months = days * 30;
        var twomonths = days * 365;
        var myDate = new Date(Date.parse(postdate));
        if (isNaN(myDate)) {
            myDate = new Date(postdate.replace(/-/g, "/"));
        }
        var nowtime = new Date();
        var longtime = nowtime.getTime() - myDate.getTime();
        var showtime = 0;
        if (longtime > months * 2) {
            return postdate;
        } else if (longtime > months) {
            return "1个月前";
        } else if (longtime > days * 7) {
            return ("1周前");
        } else if (longtime > days) {
            return (Math.floor(longtime / days) + "天前");
        } else if (longtime > hours) {
            return (Math.floor(longtime / hours) + "小时前");
        } else if (longtime > minutes) {
            return (Math.floor(longtime / minutes) + "分钟前");
        } else if (longtime > second) {
            return (Math.floor(longtime / second) + "秒前");
        } else {
            return (longtime + " error ");
        }
    },
    empty: function(mixed_var) {
        var undef, key, i, len;
        var emptyValues = [undef, null, false, 0, '', '0'];
        for (i = 0, len = emptyValues.length; i < len; i++) {
            if (mixed_var === emptyValues[i]) {
                return true;
            }
        }
        if (typeof mixed_var === 'object') {
            for (key in mixed_var) {
                return false;
            }
            return true;
        }
        return false;
    },
    trim: function(s) {
        return (s != null ? s.replace(/(^\s*)|(\s*$)/g, "") : "");
    },
    is_int: function(value) {
        var patrn = /^[0-9]*$/;
        if (patrn.exec(value) == null || value == "") {
            return false
        } else {
            return true
        }
    },
    substring: function(source, length, padding) {
        var s = this.trim(source);
        if (source.length < 1) {
            return s;
        }
        var c;
        var size = 0;
        var count = s.length;
        var buffer = [];
        for (var i = 0; i < s.length; i++) {
            c = s.charCodeAt(i);
            if (c >= 0x0080) {
                size += 2;
                count++;
            } else {
                size++;
            }
            if (size > length) {
                if (c >= 0x4e00) {
                    size -= 2;
                } else {
                    size--;
                }
                break;
            }
            buffer[buffer.length] = s.charAt(i);
        }
        if (size < count && padding != null) {
            buffer[buffer.length] = padding;
        }
        return buffer.join("");
    },
    is_array: function(source) {
        return '[object Array]' == Object.prototype.toString.call(source);
    },
    jsonToQuery: function(json) {
        var result = [],
        itemLen;
        $.each(json,
        function(item, key) {
            if (StringUtil.isArray(item)) {
                itemLen = item.length;
                while (itemLen--) {
                    result.push(key + '=' + replacer(item[itemLen], key));
                }
            } else {
                result.push(item + '=' + encodeURIComponent(key));
            }
        });
        return result.join('&');
    },
    queryToJson: function(url) {
        var query = url.substr(url.lastIndexOf('?') + 1),
        params = query.split('&'),
        len = params.length,
        result = {},
        i = 0,
        key,
        value,
        item,
        param;
        for (; i < len; i++) {
            if (!params[i]) {
                continue;
            }
            param = params[i].split('=');
            key = param[0];
            value = decodeURIComponent(param[1]);
            item = result[key];
            if ('undefined' == typeof item) {
                result[key] = value;
            } else if (StringUtil.isArray(item)) {
                item.push(value);
            } else {
                result[key] = [item, value];
            }
        }
        return result;
    },
    html: function(source, crlf) {
        if (source == null) {
            return "";
        }
        if (crlf == null) {
            crlf = "";
        }
        var c;
        var buffer = [];
        for (var i = 0,
        size = source.length; i < size; i++) {
            c = source.charAt(i);
            switch (c) {
            case '&':
                {
                    buffer[buffer.length] = "&amp;";
                    break;
                }
            case '"':
                {
                    buffer[buffer.length] = "&quot;";
                    break;
                }
            case '<':
                {
                    buffer[buffer.length] = "&lt;";
                    break;
                }
            case '>':
                {
                    buffer[buffer.length] = "&gt;";
                    break;
                }
            case '\r':
                {
                    if ((i + 1) < size) {
                        if (source.charAt(i + 1) == '\n') {
                            buffer[buffer.length] = crlf;
                            i++;
                        } else {
                            buffer[buffer.length] = c;
                        }
                    } else {
                        buffer[buffer.length] = c;
                    }
                    break;
                }
            case '\n':
                {
                    buffer[buffer.length] = crlf;
                    break;
                }
            default:
                {
                    buffer[buffer.length] = c;
                    break;
                }
            }
        }
        return buffer.join("");
    }
};
var HtmlBuild = {
    loginDialog: function(id, paramsAry) {
        var Tplstr = "";
        return tmpl(id, Tplstr, paramsAry);
    },
    userInfo: function(id, userInfo) {
        if (userInfo != null) {
            $(id).addClass('on');
        } else {
            $(id).removeClass('on');
        }
        var t = template(id + '_tmpl', {
            "user": userInfo,
            "hs_const_url": hs_const_url,
            "hs_const_domain": hs_const_domain
        });
        return t;
    }
}
if (window.UserManager == null || window.UserManager == undefined) {
    window.UserManager = Class.getInstance(null, Listener);
}
UserManager.parse = function() {
    var user = {};
    var nickName = CookieUtil.getCookie("nickname");
    var authcookie = CookieUtil.getCookie('authcookie');
    var uid = CookieUtil.getCookie('uid');
    var viplevel = CookieUtil.getCookie('viplevel');
    if ((nickName != null && nickName != "") || (authcookie != null && authcookie != undefined)) {
        user.nickName = nickName;
        return user;
    }
    return null;
};
UserManager.getUser = function() {
    return this.user;
};
UserManager.openLoginDialog = function(furl, isLoginAuthor, callback) {
    var ltype;
    var formStr = HtmlBuild.loginDialog(furl, 'ui_widget_message_dialog');
    MessageDialog.open('登录' + isLoginAuthor ? '作者中心': '红薯网', '', callback);
};
UserManager.openRegisterDialog = function(furl, isRegisgterAuthor, callback) {
    var ltype;
    var formStr = HtmlBuild.loginDialog(furl, 'ui_widget_message_dialog');
    MessageDialog.open('注册' + isLoginAuthor ? '作者': '红薯账号', '', callback);
};
UserManager.logout = function(reload, redirect) {
    jQuery.ajax({
        type: "get",
        url: hs_const_url.ajax_logout,
        dataType: "json",
        async: true,
        error: function() {},
        success: function(data) {
            this.user = null;
            CookieUtil.setCookie({
                name: "nickname",
                value: null,
                expires: -1,
                path: "/",
                domain: CookieUtil.getDomain()
            });
            CookieUtil.setCookie({
                name: "authcookie",
                value: null,
                expires: -1,
                path: "/",
                domain: CookieUtil.getDomain()
            });
            if (reload != false) {
                window.location.reload();
            } else {
                window.UserManager.trigger(null);
            }
        }
    });
    return false;
};
UserManager.bind = function(userInfo) {
    if (userInfo != null && userInfo != false) {
        window.userInfo = userInfo;
        this.trigger(userInfo);
    }
};
UserManager.checkLogin = function(force, callback) {
    if (force == true || window.userInfo == null || window.userInfo == undefined) {
        jQuery.ajax({
            type: "get",
            url: hs_const_url.ajax_userinfo,
            dataType: "jsonp",
            async: true,
            error: function() {},
            success: function(data) {
                if (data.code == 102) {
                    window.UserManager.bind(data.loginfo);
                    if (callback != null) {
                        callback(data.loginfo);
                    }
                } else if (data.code == -102) {
                    callback(false);
                }
            }
        });
    } else {
        this.trigger(window.userInfo);
    }
};
UserManager.getUserInfo = function() {
    return window.userInfo;
};